package com.xbongbong.saas.domain.dao;

import com.xbongbong.saas.domain.entity.StockFlowBillEntity;
import com.xbongbong.saas.domain.entity.StockFlowBillEntityExt;
import com.xbongbong.saas.domain.entity.StockFlowBillUpdateEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 流水记录表
 * @author lee
 * @date 2020/1/13 16:51
 * @since v1.0
 * @version v1.0
 */
@Repository
@Mapper
public interface StockFlowBillDao {
    /**
     * 插入数据
     *
     * @param stockFlowBillEntity 表单实体数据
     * @author lee
     * @date 2020/1/13 16:51
     * @since v1.0
     * @version v1.0
     **/
    Integer insert(StockFlowBillEntity stockFlowBillEntity);
    /**
     * 更新数据
     *
     * @param stockFlowBillEntity 表单实体数据
     * @author lee
     * @date 2020/1/13 16:51
     * @since v1.0
     * @version v1.0
     **/
    Integer update(StockFlowBillEntity stockFlowBillEntity);
    /**
     * 删除单条数据
     *
     * @param key 主键
     * @param corpid 公司ID
     * @author lee
     * @date 2020/1/13 16:51
     * @since v1.0
     * @version v1.0
     **/
    Integer deleteByKey(@Param("key") Long key, @Param("corpid") String corpid);
    /**
     * 根据索引查询数据
     *
     * @param key 主键
     * @param corpid 公司ID
     * @author lee
     * @date 2020/1/13 16:51
     * @since v1.0
     * @version v1.0
     **/
    StockFlowBillEntity getByKey(@Param("key") Long key, @Param("corpid") String corpid);
    /**
     * 根据索引查询数据
     *
     * @param param 查询参数
     * @author lee
     * @date 2020/1/13 16:51
     * @since v1.0
     * @version v1.0
     **/
    List<StockFlowBillEntity> findEntitys(@Param("param") Map<String, Object> param);
    /**
     * 获取数据条数
     *
     * @param param 查询参数
     * @author lee
     * @date 2020/1/13 16:51
     * @since v1.0
     * @version v1.0
     **/
    Integer getEntitysCount(@Param("param") Map<String, Object> param);

    Integer insertBatch(@Param("list") List<StockFlowBillEntity> stockFlowBillList);

    Integer updateBatch(@Param("list") Collection<StockFlowBillUpdateEntity> updateList, @Param("corpid") String corpid, @Param("warehouseKeyList") Set<String> warehouseKey);

    Integer updateGreaterThanTime(@Param("list") Collection<StockFlowBillUpdateEntity> updateList, @Param("corpid") String corpid, @Param("warehouseKeyList") Set<String> warehouseKey);

    List<StockFlowBillEntity> getLatestFlowBillByWarehouseKey(@Param("param") Map<String, Object> param);

    Integer deleteByRefIdIn(@Param("corpid") String corpid, @Param("refIdIn") List<Long> refIdIn, @Param("businessTypeIn") List<Integer> businessTypeIn);

    List<StockFlowBillEntityExt> getFlowInfo(@Param("param") Map<String, Object> param);

    Integer getGroupByEntitysCount(@Param("param")Map<String, Object> param);

    void deleteAllByCorpId(@Param("corpid") String corpid);

    void deleteByAddTime(@Param("param")Map<String, Object> param);

    List<StockFlowBillEntity> queryStockFlowbydate(@Param("param")Map<String, Object> param);

    void updateStockFlowById(@Param("list")List<StockFlowBillEntity> stockFlowBillEntityList, @Param("corpid")String corpid);

    List<StockFlowBillEntity> queryStockFlowbydateAndId(@Param("corpid")String corpid, @Param("date")Long date, @Param("list")List<Long>  productId);

    /**
     * 流水中是否存在产品
     *
     * @param corpid        公司ID
     * @param productIdList 产品ID
     * @return 1 -> 存在产品流水， 0->不存在
     */
    Long isExistProduct(@Param("corpid") String corpid, @Param("productIdList") List<Long> productIdList);

    List<StockFlowBillEntity> getStockFlowByWarehouseKey(@Param("corpid")String corpid, @Param("list")List<String> warehouseKeyList);

    StockFlowBillEntity getStockFlowBillBytime(@Param("corpid")String corpid, @Param("productId")Long productId, @Param("warehouseId")Long warehouseId);

    StockFlowBillEntity checkDate(@Param("corpid")String corpid,@Param("date")Long date,@Param("list")List<Long> productIdList);

    List<StockFlowBillEntity> getCheckDate(@Param("corpid")String corpid,@Param("date")Long date,@Param("list")List<Long> productIdList);

    StockFlowBillEntity getFirstStockFlowBillBytime(@Param("corpid")String corpid, @Param("date")Long date);
}
